package StudyCode.summary.mycollection;

import java.text.DateFormatSymbols;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class CollectionWithIterator {
	Collection<String> safeMonths;

	public Collection<String> filter(Collection<String> c) {

		Collection<String> filteredCollection = new ArrayList<String>();

		for (Iterator<String> i = c.iterator(); i.hasNext(); ) {
			String s = i.next();
			if (condition(s)) {
				filteredCollection.add(s);
			}
		}
		return filteredCollection;
	}

	public boolean condition(String s) {
		return s.contains("r");
	}

	public static void main(String[] args) {
		CollectionWithIterator om = new CollectionWithIterator();
		DateFormatSymbols dfs = new DateFormatSymbols();
		String[] monthArray = dfs.getMonths();
		Collection<String> months = Arrays.asList(monthArray);
		om.safeMonths = om.filter(months);
		System.out.println(om.safeMonths);
	}
}
